Last updated: 2019-09-12

Checks: 6 1

Knit directory: ~/Research-Local/RNAseq-Local/TCGA-Nigerian-RNAseq/

This reproducible R Markdown analysis was created with workflowr (version 1.4.0). The Checks tab describes the reproducibility checks that were applied when the results were created. The Past versions tab lists the development history.


The R Markdown is untracked by Git. To know which version of the R Markdown file created these results, you’ll want to first commit it to the Git repo. If you’re still working on the analysis, you can ignore this warning. When you’re finished, you can run wflow_publish to commit the R Markdown file and build the HTML.

Great job! The global environment was empty. Objects defined in the global environment can affect the analysis in your R Markdown file in unknown ways. For reproduciblity it’s best to always run the code in an empty environment.

The command set.seed(20190113) was run prior to running the code in the R Markdown file. Setting a seed ensures that any results that rely on randomness, e.g. subsampling or permutations, are reproducible.

Great job! Recording the operating system, R version, and package versions is critical for reproducibility.

Nice! There were no cached chunks for this analysis, so you can be confident that you successfully produced the results during this run.

Great job! Using relative paths to the files within your workflowr project makes it easier to run your code on other machines.

Great! You are using Git for version control. Tracking code development and connecting the code version to the results is critical for reproducibility. The version displayed above was the version of the Git repository at the time these results were generated.

Note that you need to be careful to ensure that all relevant files for the analysis have been committed to Git prior to generating the results (you can use wflow_publish or wflow_git_commit). workflowr only checks the R Markdown file, but you know if there are other scripts or data files that it depends on. Below is the status of the Git repository when the results were generated:


Ignored files:
    Ignored:    .DS_Store
    Ignored:    .Rproj.user/
    Ignored:    analysis/.DS_Store
    Ignored:    analysis/.Rhistory
    Ignored:    code/.DS_Store
    Ignored:    docs/.DS_Store
    Ignored:    docs/figure/.DS_Store
    Ignored:    plots/.DS_Store

Untracked files:
    Untracked:  NigerianTCGArawcountsDeSeq2-proteincoding-IHC.Rmd

Unstaged changes:
    Deleted:    analysis/NigerianTCGArawcountsDeSeq2-proteincoding-IHC.Rmd

Note that any generated files, e.g. HTML, png, CSS, etc., are not included in this status report because it is ok for generated content to have uncommitted changes.


There are no past versions. Publish this analysis with wflow_publish() to start tracking its development.


#Translation from HTSeq raw counts -> Count Matrix I have 66 TCGA patients with whole-genome sequencing data and RNAseq data as well as 48 Nigerian patients with RNA-seq data. Raw counts were initially processed using HTSeq, so HTSeq data is being formatted for use with DESeq2 and limma-voom.

FOLDER <- "/Users/parajago/Research-Local/RNAseq-Local/Inputs/NigerianTCGA_quants-proteincoding-IHC"
sampleFiles <- grep("htseq.counts",list.files(FOLDER),value=TRUE)

#Differential gene expression setup based on race (b/w/other)
sampleConditionrace <- sampleFiles
countVar2=1
for (sample in sampleConditionrace){
  if (stri_detect_fixed(sample,"LIB")==TRUE){
    sampleConditionrace[countVar2] <- "Nigerian"
    countVar2=countVar2+1
  } else if (stri_detect_fixed(sample,"black")==TRUE){
    sampleConditionrace[countVar2] <- "TCGA_black"
    countVar2=countVar2+1
  } else if (stri_detect_fixed(sample,"white")==TRUE){
    sampleConditionrace[countVar2] <- "TCGA_white"
    countVar2=countVar2+1
  } else{
    sampleConditionrace[countVar2] <- "TCGA_other"
    countVar2=countVar2+1
  }
}

#Condition based on IHC subtype 
sampleConditionIHC <- sampleFiles
countVar2=1
for (sample in sampleConditionIHC){
  if (stri_detect_fixed(sample,"Her2")==TRUE){
    sampleConditionIHC[countVar2] <- "Her2"
    countVar2=countVar2+1
  } else if (stri_detect_fixed(sample,"TNBC")==TRUE){
    sampleConditionIHC[countVar2] <- "TNBC"
    countVar2=countVar2+1
  } else if (stri_detect_fixed(sample,"HRpos")==TRUE){
    sampleConditionIHC[countVar2] <- "HRpos"
    countVar2=countVar2+1
  } else if (stri_detect_fixed(sample,"TPBC")==TRUE){
    sampleConditionIHC[countVar2] <- "TPBC"
    countVar2=countVar2+1
  } else{
    sampleConditionIHC[countVar2] <- "Other"
    countVar2=countVar2+1
  }
}

#Condition based on batch (relevant to the Nigerian patients only; no difference in batch for the TCGA patients)
batchval <- sampleFiles
countVar2=1
for (sample in batchval){
  if (stri_detect_fixed(sample,"batch1")==TRUE){
    batchval[countVar2] <- "batch1"
    countVar2=countVar2+1
  } else if (stri_detect_fixed(sample,"batch23")==TRUE){
    batchval[countVar2] <- "batch23"
    countVar2=countVar2+1
  } else if (stri_detect_fixed(sample,"batch4")==TRUE){
    batchval[countVar2] <- "batch4"
    countVar2=countVar2+1
  } else if (stri_detect_fixed(sample,"batch5")==TRUE){
    batchval[countVar2] <- "batch5"
    countVar2=countVar2+1
  } else{
    batchval[countVar2] <- "batchT"
    countVar2=countVar2+1
  }
}

sampleLOH <-sampleFiles
countVar2=1
for (sample in sampleLOH){
  if (stri_detect_fixed(sample,"noLOH")==TRUE){
    sampleLOH[countVar2] <- "noLOH"
    countVar2=countVar2+1
  } else if (stri_detect_fixed(sample,"LOH")==TRUE){
    sampleLOH[countVar2] <- "LOH"
    countVar2=countVar2+1
  } else{
    sampleLOH[countVar2] <- NA
    countVar2=countVar2+1
  }
}

table(sampleConditionrace, sampleConditionIHC)
                   sampleConditionIHC
sampleConditionrace Her2 HRpos TNBC
         Nigerian     23     6   19
         TCGA_black    0    10   20
         TCGA_white   10    10   16
sampleTable <- data.frame(sampleName=gsub(".htseq.counts","",sampleFiles),
                          fileName=sampleFiles,
                          condition1=sampleConditionrace,
                          condition2=sampleConditionIHC,
                          condition3=sampleLOH,
                          batch=batchval)

sampleTable$sampleCondition <- paste(sampleTable$condition1, sampleTable$condition2, sep=".")

ddsHTSeqMF <- DESeqDataSetFromHTSeqCount(sampleTable=sampleTable,
                                       directory=FOLDER,
                                       design=~sampleCondition)

ddsHTSeqMF <- ddsHTSeqMF[rowSums(counts(ddsHTSeqMF)) > 0, ] #Pre-filtering the dataset by removing the rows without any information about gene expression -> this removes 677 genes

#Quantile normalization Please refer to: https://parajago.github.io/TCGA-Nigerian-RNAseq/NigerianTCGArawcountsDeSeq2-pc2.html regarding comparison between the Nigerian and TCGA data sets and why quantile normalization under the limma-voom approach was chosen for primary differential expression analysis.

##Data visualization

countmatrix <- assay(ddsHTSeqMF) #Raw counts organized into matrix format from individual files
countmatrix2 <- log2(countmatrix + 1) #Basic transformation of the count data 

plot(density(countmatrix2[,1]),lwd=3,ylim=c(0,.30), main="Density of counts with log2[count]+1 transformation ONLY") 
for(i in 1:114){lines(density(countmatrix2[,i]),lwd=3)} #This demonstrates that there is a difference in distributions between the Nigerian and TCGA data with basic log transformation normalization 

Version Author Date
71cf4cd Sheila Rajagopal 2019-09-11
norm_countmatrix <- as.matrix(countmatrix2) 
norm_countmatrix = normalize.quantiles(norm_countmatrix)
plot(density(norm_countmatrix[,1]),lwd=3,ylim=c(0,.3), main="Density of counts with quantile normalization")
for(i in 1:114){lines(density(norm_countmatrix[,i]),lwd=3)} #This demonstrates the effect of comparative quantile normalization

Version Author Date
71cf4cd Sheila Rajagopal 2019-09-11
colnames (norm_countmatrix) <- colnames (countmatrix2)
rownames (norm_countmatrix) <- rownames (countmatrix2)

norm_countmatrix <- as.data.frame(norm_countmatrix)
countmatrixNigerian <- dplyr::select(norm_countmatrix, contains("LIB"))
plot(density(countmatrixNigerian[,1]),lwd=3,ylim=c(0,.3), main="Density of counts with quantile normalization - Nigerian")
for(i in 1:48){lines(density(countmatrixNigerian[,i]),lwd=3)} #This demonstrates the result of the normalized Nigerian counts separately

Version Author Date
71cf4cd Sheila Rajagopal 2019-09-11
tcgacolnames <- colnames(countmatrix)
tcgacolnames <- setdiff(tcgacolnames, colnames(countmatrixNigerian))
countmatrixTCGA <- norm_countmatrix[ , tcgacolnames]
plot(density(countmatrixTCGA[,1]),lwd=3,ylim=c(0,.3), main="Density of counts with quantile normalization - TCGA")
for(i in 1:66){
  lines(density(countmatrixTCGA[,i]),lwd=3);
#  print(colnames(countmatrix)[i])
#  invisible(readline(prompt=i))
  } #This demonstrates the result of the normalized TCGA counts separately

Version Author Date
71cf4cd Sheila Rajagopal 2019-09-11
norm_countmatrix <- as.data.frame(norm_countmatrix)
t_norm_countmatrix <- t(norm_countmatrix)

t_norm_countmatrix <- cbind (t_norm_countmatrix, sampleTable) #This binds the characteristics of the original patients to the quantile normalized counts. CBinding was checked to make sure that patients were correctly aligned to characteristics. 

quant.pca <- prcomp(t_norm_countmatrix[,1:19596])
autoplot(quant.pca, data=t_norm_countmatrix, colour='sampleCondition', main="PCA of quantile normalization results prior to DE analysis")

Version Author Date
71cf4cd Sheila Rajagopal 2019-09-11

In the raw data with log transformation only, we are able to see that there are two peaks corresponding to the two datasets (Nigerian and TCGA). The quantile normalization demonstrates a PCA that has similar clustering. Only ~20% of the distribution of the data set is explained by the PCA1, 2 of the variables.

##Differential expression setup

annotation <- as.data.frame(row.names(countmatrix))
colnames(annotation) <- c("GeneID")
annotation$temp <- gsub("[.].+", "", annotation[,1])

annotation$symbol <- mapIds(EnsDb.Hsapiens.v75,
                     keys=annotation$temp,
                     column="SYMBOL",
                     keytype="GENEID",           
                     multiVals="first")

annotation$symbol <- mapIds(EnsDb.Hsapiens.v75,
                     keys=annotation$temp,
                     column="SYMBOL",
                     keytype="GENEID",           
                     multiVals="first")

annotation$chr <- mapIds(EnsDb.Hsapiens.v75,
                     keys=annotation$temp,
                     column="SEQNAME",
                     keytype="GENEID",           
                     multiVals="first")

annotation$locstart <- mapIds(EnsDb.Hsapiens.v75,
                     keys=annotation$temp,
                     column="GENESEQSTART",
                     keytype="GENEID",
                     multiVals="first")

annotation$locend <- mapIds(EnsDb.Hsapiens.v75,
                     keys=annotation$temp,
                     column="GENESEQEND",
                     keytype="GENEID",
                     multiVals="first")
annotation$temp <- NULL

design <- t_norm_countmatrix
design <- design %>% dplyr::select(sampleCondition)

Warning: The above code chunk cached its results, but it won’t be re-run if previous chunks it depends on are updated. If you need to use caching, it is highly recommended to also set knitr::opts_chunk$set(autodep = TRUE) at the top of the file (in a chunk that is not cached). Alternatively, you can customize the option dependson for each individual chunk that is cached. Using either autodep or dependson will remove this warning. See the knitr cache options for more details.

##DE: Nigerian vs. TCGA regardless of subtype

designNvsT <- t_norm_countmatrix
designNvsT <- designNvsT %>% dplyr::select(condition1)

designNvsT$condition1 <- ifelse (designNvsT$condition1=="TCGA_white", 0, as.character(designNvsT$condition1))

designNvsT$condition1 <- ifelse (designNvsT$condition1=="TCGA_black", 1, as.character(designNvsT$condition1))

designNvsT$condition1 <- ifelse (designNvsT$condition1=="Nigerian", 2, as.character(designNvsT$condition1))

designNvsT$TCGA_white <- ifelse (designNvsT$condition1==0, 1, 0)

designNvsT$TCGA_black <- ifelse (designNvsT$condition1==1, 1, 0)

designNvsT$Nigerian <- ifelse (designNvsT$condition1==2, 1, 0)

designNvsT$condition1 <- NULL

mm <- model.matrix(~0+designNvsT$TCGA_white+designNvsT$TCGA_black+designNvsT$Nigerian)

quantids <- rownames(designNvsT)
rownames(mm) <- quantids
colnames(mm) <- c("TCGA_white", "TCGA_black", "Nigerian")

quantdata <- as.data.frame(t(counts(ddsHTSeqMF)))
quantdata <- quantdata[quantids,]
quantdata <- t(quantdata)

d0 <- DGEList(counts=quantdata, genes=annotation)
dim(d0)
[1] 19596   114
cutoff <- 10
drop <- which(apply(cpm(d0), 1, max) < cutoff)
d <- d0[-drop,] 
dim(d) # Number of genes after taking out low expressed genes
[1] 15283   114
v=voom(d,designNvsT,plot=T, normalize="quantile")

Version Author Date
71cf4cd Sheila Rajagopal 2019-09-11
contr.matrix <- makeContrasts(TCGA_white-Nigerian,levels=colnames(designNvsT))

fit <- lmFit(v, designNvsT)
fit <- contrasts.fit(fit, contrasts=contr.matrix)
fit <- eBayes(fit, trend=TRUE)
dt <- decideTests(fit)
summary(dt)
       TCGA_white - Nigerian
Down                    3613
NotSig                  7216
Up                      4454
hist(fit$p.value, ylim=c(0,3000), main="Histogram of unadjusted p-values of differential gene expression between breast cancers in\n Nigerian vs. TCGA white breast cancer patients\n quantile corrected")

Version Author Date
71cf4cd Sheila Rajagopal 2019-09-11
qvals<-p.adjust(fit$p.value[,1], method='fdr')

df_limma <- data_frame(log2FoldChange = fit$coefficients[,1], 
                       pval = fit$p.value[,1],
                       padj = qvals,
                       anno = fit$genes)

with(df_limma, plot(log2FoldChange, -log10(padj), pch=20, main="Volcano plot of differential gene expression between \nbreast cancers in Nigerian and TCGA white patients\nquantile corrected", xlim=c(-50,50), ylim=c(0,70)))
with(subset(df_limma, padj<0.05 & (2^(abs(log2FoldChange))>50)), points(log2FoldChange, -log10(padj), pch=20, col="blue"))
with(subset(df_limma, padj<0.05 & (2^(abs(log2FoldChange))>50)), textxy(log2FoldChange, -log10(padj), labs=anno$symbol, cex=.5))

Version Author Date
71cf4cd Sheila Rajagopal 2019-09-11
df_limmaprint <- as.data.frame(df_limma)

df_limmaprint$foldChange <- NA
row.pos <- which(! is.na(df_limmaprint$log2FoldChange) & 
                df_limmaprint$log2FoldChange >= 0)
row.neg <- which(! is.na(df_limmaprint$log2FoldChange) & 
                df_limmaprint$log2FoldChange < 0)
df_limmaprint$foldChange[row.pos] <- 2^df_limmaprint$log2FoldChange[row.pos]
df_limmaprint$foldChange[row.neg] <- -2^((-1) * df_limmaprint$log2FoldChange[row.neg])

df_limmaprint <- df_limmaprint %>% arrange(foldChange) %>% dplyr::filter(padj < 0.05) %>% dplyr::filter(abs(foldChange)>1.5)

top_n(df_limmaprint, 10)
top_n(df_limmaprint, -10)
write.csv(df_limmaprint, file = "TCGAwhite-Nigerian-all-DE.csv", row.names = FALSE)

contr.matrix <- makeContrasts(TCGA_black-Nigerian,levels=colnames(designNvsT))

fit <- lmFit(v, designNvsT)
fit <- contrasts.fit(fit, contrasts=contr.matrix)
fit <- eBayes(fit, trend=TRUE)
dt <- decideTests(fit)
summary(dt)
       TCGA_black - Nigerian
Down                    3305
NotSig                  8037
Up                      3941
hist(fit$p.value, ylim=c(0,3000), main="Histogram of unadjusted p-values of differential gene expression between breast cancers in\n Nigerian vs. TCGA black breast cancer patients\n quantile corrected")

Version Author Date
71cf4cd Sheila Rajagopal 2019-09-11
qvals<-p.adjust(fit$p.value[,1], method='fdr')

df_limma <- data_frame(log2FoldChange = fit$coefficients[,1], 
                       pval = fit$p.value[,1],
                       padj = qvals,
                       anno = fit$genes)

with(df_limma, plot(log2FoldChange, -log10(padj), pch=20, main="Volcano plot of differential gene expression between \nbreast cancers in Nigerian and TCGA black patients\nquantile corrected", xlim=c(-50,50), ylim=c(0,70)))
with(subset(df_limma, padj<0.05 & (2^(abs(log2FoldChange))>50)), points(log2FoldChange, -log10(padj), pch=20, col="blue"))
with(subset(df_limma, padj<0.05 & (2^(abs(log2FoldChange))>50)), textxy(log2FoldChange, -log10(padj), labs=anno$symbol, cex=.5))

Version Author Date
71cf4cd Sheila Rajagopal 2019-09-11
df_limmaprint <- as.data.frame(df_limma)

df_limmaprint$foldChange <- NA
row.pos <- which(! is.na(df_limmaprint$log2FoldChange) & 
                df_limmaprint$log2FoldChange >= 0)
row.neg <- which(! is.na(df_limmaprint$log2FoldChange) & 
                df_limmaprint$log2FoldChange < 0)
df_limmaprint$foldChange[row.pos] <- 2^df_limmaprint$log2FoldChange[row.pos]
df_limmaprint$foldChange[row.neg] <- -2^((-1) * df_limmaprint$log2FoldChange[row.neg])

df_limmaprint <- df_limmaprint %>% arrange(foldChange) %>% dplyr::filter(padj < 0.05) %>% dplyr::filter(abs(foldChange)>1.5)

top_n(df_limmaprint, 10)
top_n(df_limmaprint, -10)
write.csv(df_limmaprint, file = "TCGAblack-Nigerian-all-DE.csv", row.names = FALSE)

Warning: The above code chunk cached its results, but it won’t be re-run if previous chunks it depends on are updated. If you need to use caching, it is highly recommended to also set knitr::opts_chunk$set(autodep = TRUE) at the top of the file (in a chunk that is not cached). Alternatively, you can customize the option dependson for each individual chunk that is cached. Using either autodep or dependson will remove this warning. See the knitr cache options for more details.

##DE: Nigerian/TCGA White - TNBC

designNvsW <- design
designNvsW$sampleCondition <- ifelse (designNvsW$sampleCondition=="TCGA_white.TNBC", 0, as.character(designNvsW$sampleCondition))
designNvsW$sampleCondition <- ifelse (designNvsW$sampleCondition=="Nigerian.TNBC", 1, as.character(designNvsW$sampleCondition))

designNvsW$sampleCondition <- ifelse (designNvsW$sampleCondition==0 | designNvsW$sampleCondition==1, designNvsW$sampleCondition, NA)

designNvsW <- designNvsW %>% subset(is.na(sampleCondition)==FALSE)

designNvsW$TCGA_white.TNBC <- ifelse (designNvsW$sampleCondition==0, 1, 0)
designNvsW$Nigerian.TNBC <- ifelse (designNvsW$sampleCondition==1, 1, 0)

designNvsW$sampleCondition <- NULL

mm <- model.matrix(~0+designNvsW$TCGA_white.TNBC+designNvsW$Nigerian.TNBC)

quantids <- rownames(designNvsW)
rownames(mm) <- quantids
colnames(mm) <- c("TCGA_white", "Nigerian")

quantdata <- as.data.frame(t(counts(ddsHTSeqMF)))
quantdata <- quantdata[quantids,]
quantdata <- t(quantdata)

d0 <- DGEList(counts=quantdata, genes=annotation)

cutoff <- 10
drop <- which(apply(cpm(d0), 1, max) < cutoff)
d <- d0[-drop,] 
dim(d) # Number of genes after taking out low expressed genes
[1] 14458    35
v=voom(d,designNvsW,plot=T, normalize="quantile")

Version Author Date
71cf4cd Sheila Rajagopal 2019-09-11
contr.matrix <- makeContrasts(TCGA_white.TNBC-Nigerian.TNBC, levels=colnames(designNvsW))

fit <- lmFit(v, designNvsW)
fit <- contrasts.fit(fit, contrasts=contr.matrix)
fit <- eBayes(fit)
dt <- decideTests(fit)
summary(dt)
       TCGA_white.TNBC - Nigerian.TNBC
Down                              2573
NotSig                            8570
Up                                3315
hist(fit$p.value, ylim=c(0,3000), main="Histogram of unadjusted p-values of differential gene expression\n between TNBC breast cancers in Nigerian and TCGA white patients\n quantile corrected")

Version Author Date
71cf4cd Sheila Rajagopal 2019-09-11
qvals<-p.adjust(fit$p.value[,1], method='fdr')

df_limma <- data_frame(log2FoldChange = fit$coefficients[,1], 
                       pval = fit$p.value[,1],
                       padj = qvals,
                       anno = fit$genes)

with(df_limma, plot(log2FoldChange, -log10(padj), pch=20, main="Volcano plot of differential gene expression between TNBC \nbreast cancers in Nigerian and TCGA white breast cancer patients\nquantile corrected", xlim=c(-50,50), ylim=c(0,70)))
with(subset(df_limma, padj<0.05 & (2^(abs(log2FoldChange))>50)), points(log2FoldChange, -log10(padj), pch=20, col="blue"))
with(subset(df_limma, padj<0.05 & (2^(abs(log2FoldChange))>50)), textxy(log2FoldChange, -log10(padj), labs=anno$symbol, cex=.5))

Version Author Date
71cf4cd Sheila Rajagopal 2019-09-11
df_limmaprint <- as.data.frame(df_limma)

df_limmaprint$foldChange <- NA
row.pos <- which(! is.na(df_limmaprint$log2FoldChange) & 
                df_limmaprint$log2FoldChange >= 0)
row.neg <- which(! is.na(df_limmaprint$log2FoldChange) & 
                df_limmaprint$log2FoldChange < 0)
df_limmaprint$foldChange[row.pos] <- 2^df_limmaprint$log2FoldChange[row.pos]
df_limmaprint$foldChange[row.neg] <- -2^((-1) * df_limmaprint$log2FoldChange[row.neg])

df_limmaprint <- df_limmaprint %>% arrange(foldChange) %>% dplyr::filter(padj < 0.05) %>% dplyr::filter(abs(foldChange)>1.5)

top_n(df_limmaprint, 10, foldChange)
top_n(df_limmaprint, -10, foldChange)
write.csv(df_limmaprint, file = "Nigerian-TCGAwhite-TNBC.csv", row.names = FALSE)

Warning: The above code chunk cached its results, but it won’t be re-run if previous chunks it depends on are updated. If you need to use caching, it is highly recommended to also set knitr::opts_chunk$set(autodep = TRUE) at the top of the file (in a chunk that is not cached). Alternatively, you can customize the option dependson for each individual chunk that is cached. Using either autodep or dependson will remove this warning. See the knitr cache options for more details.

##DE: Nigerian/TCGA Black - TNBC

designNvsB <- design
designNvsB$sampleCondition <- ifelse (designNvsB$sampleCondition=="TCGA_black.TNBC", 0, as.character(designNvsB$sampleCondition))
designNvsB$sampleCondition <- ifelse (designNvsB$sampleCondition=="Nigerian.TNBC", 1, as.character(designNvsB$sampleCondition))

designNvsB$sampleCondition <- ifelse (designNvsB$sampleCondition==0 | designNvsB$sampleCondition==1, designNvsB$sampleCondition, NA)

designNvsB <- designNvsB %>% subset(is.na(sampleCondition)==FALSE)

designNvsB$TCGA_black.TNBC <- ifelse (designNvsB$sampleCondition==0, 1, 0)
designNvsB$Nigerian.TNBC <- ifelse (designNvsB$sampleCondition==1, 1, 0)

designNvsB$sampleCondition <- NULL

mm <- model.matrix(~0+designNvsB$TCGA_black.TNBC+designNvsB$Nigerian.TNBC)

quantids <- rownames(designNvsB)
rownames(mm) <- quantids
colnames(mm) <- c("TCGA_black", "Nigerian")

quantdata <- as.data.frame(t(counts(ddsHTSeqMF)))
quantdata <- quantdata[quantids,]
quantdata <- t(quantdata)

d0 <- DGEList(counts=quantdata, genes=annotation)

cutoff <- 10
drop <- which(apply(cpm(d0), 1, max) < cutoff)
d <- d0[-drop,] 
dim(d) # Number of genes after taking out low expressed genes
[1] 14573    39
v=voom(d,designNvsB,plot=T, normalize="quantile")

Version Author Date
71cf4cd Sheila Rajagopal 2019-09-11
contr.matrix <- makeContrasts(TCGA_black.TNBC-Nigerian.TNBC, levels=colnames(designNvsB))

fit <- lmFit(v, designNvsB)
fit <- contrasts.fit(fit, contrasts=contr.matrix)
fit <- eBayes(fit)
dt <- decideTests(fit)
summary(dt)
       TCGA_black.TNBC - Nigerian.TNBC
Down                              2633
NotSig                            8853
Up                                3087
hist(fit$p.value, ylim=c(0,3000), main="Histogram of unadjusted p-values of differential gene expression\n between TNBC breast cancers in Nigerian and TCGA black patients\n quantile corrected")

Version Author Date
71cf4cd Sheila Rajagopal 2019-09-11
qvals<-p.adjust(fit$p.value[,1], method='fdr')

df_limma <- data_frame(log2FoldChange = fit$coefficients[,1], 
                       pval = fit$p.value[,1],
                       padj = qvals,
                       anno = fit$genes)

with(df_limma, plot(log2FoldChange, -log10(padj), pch=20, main="Volcano plot of differential gene expression between TNBC \nbreast cancers in Nigerian and TCGA black breast cancer patients\nquantile corrected", xlim=c(-50,50), ylim=c(0,70)))
with(subset(df_limma, padj<0.05 & (2^(abs(log2FoldChange))>50)), points(log2FoldChange, -log10(padj), pch=20, col="blue"))
with(subset(df_limma, padj<0.05 & (2^(abs(log2FoldChange))>50)), textxy(log2FoldChange, -log10(padj), labs=anno$symbol, cex=.5))

Version Author Date
71cf4cd Sheila Rajagopal 2019-09-11
df_limmaprint <- as.data.frame(df_limma)

df_limmaprint$foldChange <- NA
row.pos <- which(! is.na(df_limmaprint$log2FoldChange) & 
                df_limmaprint$log2FoldChange >= 0)
row.neg <- which(! is.na(df_limmaprint$log2FoldChange) & 
                df_limmaprint$log2FoldChange < 0)
df_limmaprint$foldChange[row.pos] <- 2^df_limmaprint$log2FoldChange[row.pos]
df_limmaprint$foldChange[row.neg] <- -2^((-1) * df_limmaprint$log2FoldChange[row.neg])

df_limmaprint <- df_limmaprint %>% arrange(foldChange) %>% dplyr::filter(padj < 0.05) %>% dplyr::filter(abs(foldChange)>1.5)

top_n(df_limmaprint, 10, foldChange)
top_n(df_limmaprint, -10, foldChange)
write.csv(df_limmaprint, file = "Nigerian-TCGAblack-TNBC.csv", row.names = FALSE)

Warning: The above code chunk cached its results, but it won’t be re-run if previous chunks it depends on are updated. If you need to use caching, it is highly recommended to also set knitr::opts_chunk$set(autodep = TRUE) at the top of the file (in a chunk that is not cached). Alternatively, you can customize the option dependson for each individual chunk that is cached. Using either autodep or dependson will remove this warning. See the knitr cache options for more details.

##DE: Nigerian/TCGA White - HR+2-

designNvsWHR <- design
designNvsWHR$sampleCondition <- ifelse (designNvsWHR$sampleCondition=="TCGA_white.HRpos", 0, as.character(designNvsWHR$sampleCondition))
designNvsWHR$sampleCondition <- ifelse (designNvsWHR$sampleCondition=="Nigerian.HRpos", 1, as.character(designNvsWHR$sampleCondition))

designNvsWHR$sampleCondition <- ifelse (designNvsWHR$sampleCondition==0 | designNvsWHR$sampleCondition==1, designNvsWHR$sampleCondition, NA)

designNvsWHR <- designNvsWHR %>% subset(is.na(sampleCondition)==FALSE)

designNvsWHR$TCGA_white.HRpos <- ifelse (designNvsWHR$sampleCondition==0, 1, 0)
designNvsWHR$Nigerian.HRpos <- ifelse (designNvsWHR$sampleCondition==1, 1, 0)

designNvsWHR$sampleCondition <- NULL

mm <- model.matrix(~0+designNvsWHR$TCGA_white.HRpos+designNvsWHR$Nigerian.HRpos)

quantids <- rownames(designNvsWHR)
rownames(mm) <- quantids
colnames(mm) <- c("TCGA_white", "Nigerian")

quantdata <- as.data.frame(t(counts(ddsHTSeqMF)))
quantdata <- quantdata[quantids,]
quantdata <- t(quantdata)

d0 <- DGEList(counts=quantdata, genes=annotation)

cutoff <- 10
drop <- which(apply(cpm(d0), 1, max) < cutoff)
d <- d0[-drop,] 
dim(d) # Number of genes after taking out low expressed genes
[1] 13188    16
v=voom(d,designNvsWHR,plot=T, normalize="quantile")

Version Author Date
71cf4cd Sheila Rajagopal 2019-09-11
contr.matrix <- makeContrasts(TCGA_white.HRpos-Nigerian.HRpos, levels=colnames(designNvsWHR))

fit <- lmFit(v, designNvsWHR)
fit <- contrasts.fit(fit, contrasts=contr.matrix)
fit <- eBayes(fit)
dt <- decideTests(fit)
summary(dt)
       TCGA_white.HRpos - Nigerian.HRpos
Down                                1443
NotSig                             10021
Up                                  1724
hist(fit$p.value, ylim=c(0,3000), main="Histogram of unadjusted p-values of differential gene expression\n between HR-positive breast cancers in Nigerian and TCGA white patients\n quantile corrected")

Version Author Date
71cf4cd Sheila Rajagopal 2019-09-11
qvals<-p.adjust(fit$p.value[,1], method='fdr')

df_limma <- data_frame(log2FoldChange = fit$coefficients[,1], 
                       pval = fit$p.value[,1],
                       padj = qvals,
                       anno = fit$genes)

with(df_limma, plot(log2FoldChange, -log10(padj), pch=20, main="Volcano plot of differential gene expression between HR-postive \nbreast cancers in Nigerian and TCGA white breast cancer patients\nquantile corrected", xlim=c(-50,50), ylim=c(0,70)))
with(subset(df_limma, padj<0.05 & (2^(abs(log2FoldChange))>50)), points(log2FoldChange, -log10(padj), pch=20, col="blue"))
with(subset(df_limma, padj<0.05 & (2^(abs(log2FoldChange))>50)), textxy(log2FoldChange, -log10(padj), labs=anno$symbol, cex=.5))

Version Author Date
71cf4cd Sheila Rajagopal 2019-09-11
df_limmaprint <- as.data.frame(df_limma)

df_limmaprint$foldChange <- NA
row.pos <- which(! is.na(df_limmaprint$log2FoldChange) & 
                df_limmaprint$log2FoldChange >= 0)
row.neg <- which(! is.na(df_limmaprint$log2FoldChange) & 
                df_limmaprint$log2FoldChange < 0)
df_limmaprint$foldChange[row.pos] <- 2^df_limmaprint$log2FoldChange[row.pos]
df_limmaprint$foldChange[row.neg] <- -2^((-1) * df_limmaprint$log2FoldChange[row.neg])

df_limmaprint <- df_limmaprint %>% arrange(foldChange) %>% dplyr::filter(padj < 0.05) %>% dplyr::filter(abs(foldChange)>1.5)

top_n(df_limmaprint, 10, foldChange)
top_n(df_limmaprint, -10, foldChange)
write.csv(df_limmaprint, file = "TCGA_white-Nigerian-HRpos.csv", row.names = FALSE)

Warning: The above code chunk cached its results, but it won’t be re-run if previous chunks it depends on are updated. If you need to use caching, it is highly recommended to also set knitr::opts_chunk$set(autodep = TRUE) at the top of the file (in a chunk that is not cached). Alternatively, you can customize the option dependson for each individual chunk that is cached. Using either autodep or dependson will remove this warning. See the knitr cache options for more details.

##DE: Nigerian/TCGA Black - HR+2-

designNvsBHR <- design
designNvsBHR$sampleCondition <- ifelse (designNvsBHR$sampleCondition=="TCGA_black.HRpos", 0, as.character(designNvsBHR$sampleCondition))
designNvsBHR$sampleCondition <- ifelse (designNvsBHR$sampleCondition=="Nigerian.HRpos", 1, as.character(designNvsBHR$sampleCondition))

designNvsBHR$sampleCondition <- ifelse (designNvsBHR$sampleCondition==0 | designNvsBHR$sampleCondition==1, designNvsBHR$sampleCondition, NA)

designNvsBHR <- designNvsBHR %>% subset(is.na(sampleCondition)==FALSE)

designNvsBHR$TCGA_black.HRpos <- ifelse (designNvsBHR$sampleCondition==0, 1, 0)
designNvsBHR$Nigerian.HRpos <- ifelse (designNvsBHR$sampleCondition==1, 1, 0)

designNvsBHR$sampleCondition <- NULL

mm <- model.matrix(~0+designNvsBHR$TCGA_black.HRpos+designNvsBHR$Nigerian.HRpos)

quantids <- rownames(designNvsBHR)
rownames(mm) <- quantids
colnames(mm) <- c("TCGA_black", "Nigerian")

quantdata <- as.data.frame(t(counts(ddsHTSeqMF)))
quantdata <- quantdata[quantids,]
quantdata <- t(quantdata)

d0 <- DGEList(counts=quantdata, genes=annotation)

cutoff <- 10
drop <- which(apply(cpm(d0), 1, max) < cutoff)
d <- d0[-drop,] 
dim(d) # Number of genes after taking out low expressed genes
[1] 13334    16
v=voom(d,designNvsBHR,plot=T, normalize="quantile")

Version Author Date
71cf4cd Sheila Rajagopal 2019-09-11
contr.matrix <- makeContrasts(TCGA_black.HRpos-Nigerian.HRpos, levels=colnames(designNvsBHR))

fit <- lmFit(v, designNvsBHR)
fit <- contrasts.fit(fit, contrasts=contr.matrix)
fit <- eBayes(fit)
dt <- decideTests(fit)
summary(dt)
       TCGA_black.HRpos - Nigerian.HRpos
Down                                 734
NotSig                             12080
Up                                   520
hist(fit$p.value, ylim=c(0,3000), main="Histogram of unadjusted p-values of differential gene expression\n between HR-positive breast cancers in Nigerian and TCGA black patients\n quantile corrected")

Version Author Date
71cf4cd Sheila Rajagopal 2019-09-11
qvals<-p.adjust(fit$p.value[,1], method='fdr')

df_limma <- data_frame(log2FoldChange = fit$coefficients[,1], 
                       pval = fit$p.value[,1],
                       padj = qvals,
                       anno = fit$genes)

with(df_limma, plot(log2FoldChange, -log10(padj), pch=20, main="Volcano plot of differential gene expression between HR-positive \nbreast cancers in Nigerian and TCGA black breast cancer patients\nquantile corrected", xlim=c(-50,50), ylim=c(0,70)))
with(subset(df_limma, padj<0.05 & (2^(abs(log2FoldChange))>50)), points(log2FoldChange, -log10(padj), pch=20, col="blue"))
with(subset(df_limma, padj<0.05 & (2^(abs(log2FoldChange))>50)), textxy(log2FoldChange, -log10(padj), labs=anno$symbol, cex=.5))

Version Author Date
71cf4cd Sheila Rajagopal 2019-09-11
df_limmaprint <- as.data.frame(df_limma)

df_limmaprint$foldChange <- NA
row.pos <- which(! is.na(df_limmaprint$log2FoldChange) & 
                df_limmaprint$log2FoldChange >= 0)
row.neg <- which(! is.na(df_limmaprint$log2FoldChange) & 
                df_limmaprint$log2FoldChange < 0)
df_limmaprint$foldChange[row.pos] <- 2^df_limmaprint$log2FoldChange[row.pos]
df_limmaprint$foldChange[row.neg] <- -2^((-1) * df_limmaprint$log2FoldChange[row.neg])

df_limmaprint <- df_limmaprint %>% arrange(foldChange) %>% dplyr::filter(padj < 0.05) %>% dplyr::filter(abs(foldChange)>1.5)

top_n(df_limmaprint, 10, foldChange)
top_n(df_limmaprint, -10, foldChange)
write.csv(df_limmaprint, file = "TCGAblack-Nigerian-HRpos.csv", row.names = FALSE)

Warning: The above code chunk cached its results, but it won’t be re-run if previous chunks it depends on are updated. If you need to use caching, it is highly recommended to also set knitr::opts_chunk$set(autodep = TRUE) at the top of the file (in a chunk that is not cached). Alternatively, you can customize the option dependson for each individual chunk that is cached. Using either autodep or dependson will remove this warning. See the knitr cache options for more details.

##DE: Nigerian/TCGA White - HER2 (no TCGA Black HER2+ patients)

designNvsWHER2 <- design
designNvsWHER2$sampleCondition <- ifelse (designNvsWHER2$sampleCondition=="TCGA_white.Her2", 0, as.character(designNvsWHER2$sampleCondition))
designNvsWHER2$sampleCondition <- ifelse (designNvsWHER2$sampleCondition=="Nigerian.Her2", 1, as.character(designNvsWHER2$sampleCondition))

designNvsWHER2$sampleCondition <- ifelse (designNvsWHER2$sampleCondition==0 | designNvsWHER2$sampleCondition==1, designNvsWHER2$sampleCondition, NA)

designNvsWHER2 <- designNvsWHER2 %>% subset(is.na(sampleCondition)==FALSE)

designNvsWHER2$TCGA_white.Her2 <- ifelse (designNvsWHER2$sampleCondition==0, 1, 0)
designNvsWHER2$Nigerian.Her2 <- ifelse (designNvsWHER2$sampleCondition==1, 1, 0)

designNvsWHER2$sampleCondition <- NULL

mm <- model.matrix(~0+designNvsWHER2$TCGA_white.Her2+designNvsWHER2$Nigerian.Her2)

quantids <- rownames(designNvsWHER2)
rownames(mm) <- quantids
colnames(mm) <- c("TCGA_white", "Nigerian")

quantdata <- as.data.frame(t(counts(ddsHTSeqMF)))
quantdata <- quantdata[quantids,]
quantdata <- t(quantdata)

d0 <- DGEList(counts=quantdata, genes=annotation)

cutoff <- 10
drop <- which(apply(cpm(d0), 1, max) < cutoff)
d <- d0[-drop,] 
dim(d) # Number of genes after taking out low expressed genes
[1] 14148    33
v=voom(d,designNvsWHER2,plot=T, normalize="quantile")

Version Author Date
71cf4cd Sheila Rajagopal 2019-09-11
contr.matrix <- makeContrasts(TCGA_white.Her2-Nigerian.Her2, levels=colnames(designNvsWHER2))

fit <- lmFit(v, designNvsWHER2)
fit <- contrasts.fit(fit, contrasts=contr.matrix)
fit <- eBayes(fit)
dt <- decideTests(fit)
summary(dt)
       TCGA_white.Her2 - Nigerian.Her2
Down                              1147
NotSig                           11167
Up                                1834
hist(fit$p.value, ylim=c(0,3000), main="Histogram of unadjusted p-values of differential gene expression\n between Her2+ breast cancers in Nigerian and TCGA white patients\n quantile corrected")

Version Author Date
71cf4cd Sheila Rajagopal 2019-09-11
qvals<-p.adjust(fit$p.value[,1], method='fdr')

df_limma <- data_frame(log2FoldChange = fit$coefficients[,1], 
                       pval = fit$p.value[,1],
                       padj = qvals,
                       anno = fit$genes)

with(df_limma, plot(log2FoldChange, -log10(padj), pch=20, main="Volcano plot of differential gene expression between Her2+ \nbreast cancers in Nigerian and TCGA white breast cancer patients\nquantile corrected", xlim=c(-50,50), ylim=c(0,70)))
with(subset(df_limma, padj<0.05 & (2^(abs(log2FoldChange))>50)), points(log2FoldChange, -log10(padj), pch=20, col="blue"))
with(subset(df_limma, padj<0.05 & (2^(abs(log2FoldChange))>50)), textxy(log2FoldChange, -log10(padj), labs=anno$symbol, cex=.5))

Version Author Date
71cf4cd Sheila Rajagopal 2019-09-11
df_limmaprint <- as.data.frame(df_limma)

df_limmaprint$foldChange <- NA
row.pos <- which(! is.na(df_limmaprint$log2FoldChange) & 
                df_limmaprint$log2FoldChange >= 0)
row.neg <- which(! is.na(df_limmaprint$log2FoldChange) & 
                df_limmaprint$log2FoldChange < 0)
df_limmaprint$foldChange[row.pos] <- 2^df_limmaprint$log2FoldChange[row.pos]
df_limmaprint$foldChange[row.neg] <- -2^((-1) * df_limmaprint$log2FoldChange[row.neg])

df_limmaprint <- df_limmaprint %>% arrange(foldChange) %>% dplyr::filter(padj < 0.05) %>% dplyr::filter(abs(foldChange)>1.5)

top_n(df_limmaprint, 10, foldChange)
top_n(df_limmaprint, -10, foldChange)
write.csv(df_limmaprint, file = "TCGAwhite-Nigerian-Her2.csv", row.names = FALSE)

Warning: The above code chunk cached its results, but it won’t be re-run if previous chunks it depends on are updated. If you need to use caching, it is highly recommended to also set knitr::opts_chunk$set(autodep = TRUE) at the top of the file (in a chunk that is not cached). Alternatively, you can customize the option dependson for each individual chunk that is cached. Using either autodep or dependson will remove this warning. See the knitr cache options for more details.

##DE: Nigerian/TCGA - HER2 14q LOH

design <- t_norm_countmatrix
designNvsTLOH <- design %>% dplyr::select(condition3)

designNvsTLOH$condition3 <- ifelse (designNvsTLOH$condition3=="noLOH", 0, as.character(designNvsTLOH$condition3))
designNvsTLOH$condition3 <- ifelse (designNvsTLOH$condition3=="LOH", 1, as.character(designNvsTLOH$condition3))

designNvsTLOH$condition3 <- ifelse (designNvsTLOH$condition3==0 | designNvsTLOH$condition3==1, designNvsTLOH$condition3, NA)

designNvsTLOH <- designNvsTLOH %>% subset(is.na(condition3)==FALSE)

designNvsTLOH$noLOH <- ifelse (designNvsTLOH$condition3==0, 1, 0)
designNvsTLOH$LOH <- ifelse (designNvsTLOH$condition3==1, 1, 0)

designNvsTLOH$condition3 <- NULL

mm <- model.matrix(~0+designNvsTLOH$noLOH+designNvsTLOH$LOH)

quantids <- rownames(designNvsTLOH)
rownames(mm) <- quantids
colnames(mm) <- c("noLOH", "LOH")

quantdata <- as.data.frame(t(counts(ddsHTSeqMF)))
quantdata <- quantdata[quantids,]
quantdata <- t(quantdata)

d0 <- DGEList(counts=quantdata, genes=annotation)

cutoff <- 10
drop <- which(apply(cpm(d0), 1, max) < cutoff)
d <- d0[-drop,] 
dim(d) # Number of genes after taking out low expressed genes
[1] 13844    21
v=voom(d,designNvsTLOH,plot=T, normalize="quantile")

Version Author Date
71cf4cd Sheila Rajagopal 2019-09-11
contr.matrix <- makeContrasts(noLOH-LOH, levels=colnames(designNvsTLOH))

fit <- lmFit(v, designNvsTLOH)
fit <- contrasts.fit(fit, contrasts=contr.matrix)
fit <- eBayes(fit)
dt <- decideTests(fit)
summary(dt)
       noLOH - LOH
Down             0
NotSig       13844
Up               0

Warning: The above code chunk cached its results, but it won’t be re-run if previous chunks it depends on are updated. If you need to use caching, it is highly recommended to also set knitr::opts_chunk$set(autodep = TRUE) at the top of the file (in a chunk that is not cached). Alternatively, you can customize the option dependson for each individual chunk that is cached. Using either autodep or dependson will remove this warning. See the knitr cache options for more details.

No significant differential expression was identified via quantile normalization/voom, which is expected as this method can be overly convservative for inter-group differential expression estimation. We have previously validated DESeq2 for inter-Nigerian comparison.

sampleTable2 <- data.frame(sampleName=gsub(".htseq.counts","",sampleFiles),
                          fileName=sampleFiles,
                          sampleCondition=sampleLOH)

sampleTable2 <- sampleTable2 %>% subset(is.na(sampleCondition)==FALSE)

ddsHTSeqMF2 <- DESeqDataSetFromHTSeqCount(
                                      sampleTable=sampleTable2,
                                      directory=FOLDER,
                                      design=~sampleCondition)

ddsHTSeqMF2 <- ddsHTSeqMF2[rowSums(counts(ddsHTSeqMF2)) > 0, ] #Pre-filtering the dataset by removing the rows without any  information about gene expression

dds <- estimateSizeFactors(ddsHTSeqMF2) #The size factor is the median ratio of the sample over a "pseudosample": for each gene, the geometric mean of all samples. This accounts for sequencing depth. 

vsd <- vst(ddsHTSeqMF2, blind=FALSE) #Variance-stabilizing transformation, only using this since >50 samples

plotPCA(vsd, intgroup=c("sampleCondition"))

Version Author Date
71cf4cd Sheila Rajagopal 2019-09-11
ddsMF <- DESeq(ddsHTSeqMF2)
resultsNames(ddsMF)
[1] "Intercept"                    "sampleCondition_noLOH_vs_LOH"
fc = 1.5 #Subsequent threshold of signifcance for log2 fold change -> 0.58 = log2(1.5)
fdr = 0.05 #Subsequent threshold of significance for p-value (adjusted by FDR)

cat("MA Plot: Differential expression based on 14q LOH presence")
MA Plot: Differential expression based on 14q LOH presence
res <- lfcShrink(ddsMF, coef="sampleCondition_noLOH_vs_LOH", type="ashr", optmethod = "mixEM")
DESeq2::plotMA(res, ylim=c(-10,10), xlim=c(0.1,200))

Version Author Date
71cf4cd Sheila Rajagopal 2019-09-11
diffLOH<- results(ddsMF, contrast=c("sampleCondition", "noLOH", "LOH"), pAdjustMethod ="fdr", alpha=fdr)

diffLOH$foldChange <- NA
row.pos <- which(! is.na(diffLOH$log2FoldChange) & 
                diffLOH$log2FoldChange >= 0)
row.neg <- which(! is.na(diffLOH$log2FoldChange) & 
                diffLOH$log2FoldChange < 0)
diffLOH$foldChange[row.pos] <- 2^diffLOH$log2FoldChange[row.pos]
diffLOH$foldChange[row.neg] <- -2^((-1) * diffLOH$log2FoldChange[row.neg])

nrow(diffLOH)
[1] 19071
diffLOH <- diffLOH[(diffLOH$foldChange > fc | diffLOH$foldChange < -fc),] 
diffLOH <- subset(diffLOH, padj < fdr)
nrow(diffLOH)
[1] 100
restemp <- lfcShrink(ddsMF, contrast=c("sampleCondition", "noLOH", "LOH"), res = diffLOH, type="ashr", optmethod = "mixEM")

restemp$temp <- row.names(restemp)
restemp$temp <- gsub("[.].+", "", restemp$temp)

restemp$symbol <- mapIds(EnsDb.Hsapiens.v75,
                     keys=restemp$temp,
                     column="SYMBOL",
                     keytype="GENEID",           
                     multiVals="first")

with(restemp, plot(log2FoldChange, -log10(padj), pch=20, main="Volcano plot of differential gene expression between \nbreast cancers in Nigerian patients with and without 14q LOH", xlim=c(-60,60), ylim=c(0,60)))
with(subset(restemp, padj<0.05 & (2^(abs(log2FoldChange))>50)), points(log2FoldChange, -log10(padj), pch=20, col="blue"))
with(subset(restemp, padj<0.05 & (2^(abs(log2FoldChange))>50)), textxy(log2FoldChange, -log10(padj), labs=symbol, cex=.5))

Version Author Date
71cf4cd Sheila Rajagopal 2019-09-11
diffLOHtable <- as.data.frame(diffLOH)
diffLOHtable$temp <- row.names(diffLOH)
diffLOHtable$temp <- gsub("[.].+", "", diffLOHtable$temp)

diffLOHtable$symbol <- mapIds(EnsDb.Hsapiens.v75,
                     keys=diffLOHtable$temp,
                     column="SYMBOL",
                     keytype="GENEID",           
                     multiVals="first")

diffLOHtable$biotype <- mapIds(EnsDb.Hsapiens.v75,
                     keys=diffLOHtable$temp,
                     column="GENEBIOTYPE",
                     keytype="GENEID",           
                     multiVals="first")

diffLOHtable$chr <- mapIds(EnsDb.Hsapiens.v75,
                     keys=diffLOHtable$temp,
                     column="SEQNAME",
                     keytype="GENEID",           
                     multiVals="first")

diffLOHtable$locstart <- mapIds(EnsDb.Hsapiens.v75,
                     keys=diffLOHtable$temp,
                     column="GENESEQSTART",
                     keytype="GENEID",
                     multiVals="first")

diffLOHtable$locend <- mapIds(EnsDb.Hsapiens.v75,
                     keys=diffLOHtable$temp,
                     column="GENESEQEND",
                     keytype="GENEID",
                     multiVals="first")

diffLOHtable$temp <- NULL

diffLOHtable <- diffLOHtable %>% arrange(foldChange) %>% dplyr::filter(padj < 0.05) %>% dplyr::filter(abs(foldChange)>1.5)

top_n(diffLOHtable, 10, foldChange)
top_n(diffLOHtable, -10, foldChange)
diffLOHtable$baseMean <- NULL
write.csv(diffLOHtable, file = "DE-LOH.csv", row.names =FALSE)

Warning: The above code chunk cached its results, but it won’t be re-run if previous chunks it depends on are updated. If you need to use caching, it is highly recommended to also set knitr::opts_chunk$set(autodep = TRUE) at the top of the file (in a chunk that is not cached). Alternatively, you can customize the option dependson for each individual chunk that is cached. Using either autodep or dependson will remove this warning. See the knitr cache options for more details.

diffLOHpath <- results(ddsMF, contrast=c("sampleCondition", "noLOH", "LOH"), pAdjustMethod ="fdr", alpha=fdr)

diffLOHpath <- as.data.frame(diffLOHpath)

diffLOHpath$foldChange <- NA
row.pos <- which(! is.na(diffLOHpath$log2FoldChange) & 
                diffLOHpath$log2FoldChange >= 0)
row.neg <- which(! is.na(diffLOHpath$log2FoldChange) & 
                diffLOHpath$log2FoldChange < 0)
diffLOHpath$foldChange[row.pos] <- 2^diffLOHpath$log2FoldChange[row.pos]
diffLOHpath$foldChange[row.neg] <- -2^((-1) * diffLOHpath$log2FoldChange[row.neg])

diffLOHpath$ENSEMBL <- row.names(diffLOHpath)
diffLOHpath$temp <- row.names(diffLOHpath)
diffLOHpath$temp <- gsub("[.].+", "", diffLOHpath$temp)

diffLOHpath$SYMBOL <- mapIds(EnsDb.Hsapiens.v75,
                     keys=diffLOHpath$temp,
                     column="SYMBOL",
                     keytype="GENEID",           
                     multiVals="first")

diffLOHpath$baseMean <- NULL
diffLOHpath$log2FoldChange <- NULL
diffLOHpath$temp <- NULL

diffLOHpath.flt <- diffLOHpath[(diffLOHpath$foldChange > fc | diffLOHpath$foldChange < -fc),] 
diffLOHpath.flt <- subset(diffLOHpath, padj < fdr)

genes.all <- diffLOHpath
genes.sig <- diffLOHpath.flt
genes.all$ENSEMBL <- gsub('[.]\\d+', '', genes.all$ENSEMBL, perl = TRUE)
genes.sig$ENSEMBL <- gsub('[.]\\d+', '', genes.sig$ENSEMBL, perl = TRUE)

genes.all.anno <- bitr(geneID   =  genes.all$ENSEMBL, 
                      fromType = 'GENEID', 
                      toType   = c('ENTREZID', 'SYMBOL'), 
                      OrgDb    = 'EnsDb.Hsapiens.v75', 
                      drop     = TRUE)

genes.all.anno <- genes.all.anno[
    which(! duplicated(genes.all.anno$ENTREZID)), ]
row.names(genes.all.anno) <- genes.all.anno$ENTREZID

genes.all.anno$ENSEMBL <- genes.all.anno$GENEID
genes.all.anno$GENEID <- NULL

genes.all.anno <- merge(genes.all.anno, genes.all, by = 'ENSEMBL')
row.names(genes.all.anno) <- genes.all.anno$ENTREZID

genes.sig.anno <- genes.all.anno[genes.all.anno$ENSEMBL %in% 
                                genes.sig$ENSEMBL,]

gene.list <- genes.all.anno$foldChange
names(gene.list) <- genes.all.anno$ENTREZID
gene.list <- sort(gene.list, decreasing = TRUE)

ego <- enrichGO(gene          = genes.sig.anno$ENTREZID,
                universe      = as.character(genes.all.anno$ENTREZID),
                OrgDb         = 'org.Hs.eg.db',
                ont           = "BP",
                pAdjustMethod = "fdr",
                pvalueCutoff  = 0.05,
                readable      = TRUE)

as.data.frame(ego)
save(ego, file="GO-LOH.significantgenes.fdr0.05.fc1.5.enrichGO.RData")
write.csv(ego, file="GO-LOH.significantgenes.fdr0.05.fc1.5.enrichGO.csv")

options(jupyter.plot_mimetypes = "image/svg+xml") 
options(repr.plot.width = 10, repr.plot.height = 5)

egokegg <- ego
for(i in 1:5) { 
  egokegg <- dropGO(egokegg, level = i)
}

p1 <- barplot(egokegg)
p2 <- dotplot(egokegg)

kk <- enrichKEGG(gene          = genes.sig.anno$ENTREZID,
                 universe      = as.character(genes.all.anno$ENTREZID),
                 organism      = "hsa",
                 pAdjustMethod = "fdr",
                 pvalueCutoff  = 0.05)

plot(p1)

plot(p2)

save(kk, file="GO-LOH.significantgenes.fdr0.05.fc1.5.enrichKEGG.RData")
write.csv(kk@result, file="GO-LOH.significantgenes.fdr0.05.fc1.5.enrichKEGG.csv")

Warning: The above code chunk cached its results, but it won’t be re-run if previous chunks it depends on are updated. If you need to use caching, it is highly recommended to also set knitr::opts_chunk$set(autodep = TRUE) at the top of the file (in a chunk that is not cached). Alternatively, you can customize the option dependson for each individual chunk that is cached. Using either autodep or dependson will remove this warning. See the knitr cache options for more details.


sessionInfo()
R version 3.6.0 (2019-04-26)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Sierra 10.12.6

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
 [1] parallel  stats4    grid      stats     graphics  grDevices utils    
 [8] datasets  methods   base     

other attached packages:
 [1] AnnotationHub_2.16.1        BiocFileCache_1.8.0        
 [3] dbplyr_1.4.2                Glimma_1.12.0              
 [5] RColorBrewer_1.1-2          preprocessCore_1.46.0      
 [7] ashr_2.2-32                 ggfortify_0.4.7            
 [9] calibrate_1.7.2             MASS_7.3-51.4              
[11] sva_3.32.1                  mgcv_1.8-28                
[13] nlme_3.1-140                EnsDb.Hsapiens.v75_2.99.0  
[15] ensembldb_2.8.0             AnnotationFilter_1.8.0     
[17] GenomicFeatures_1.36.1      hexbin_1.27.3              
[19] stringi_1.4.3               dplyr_0.8.1                
[21] affy_1.62.0                 checkmate_1.9.3            
[23] pathview_1.24.0             org.Hs.eg.db_3.8.2         
[25] AnnotationDbi_1.46.0        clusterProfiler_3.12.0     
[27] pheatmap_1.0.12             genefilter_1.66.0          
[29] vsn_3.52.0                  RUVSeq_1.18.0              
[31] EDASeq_2.18.0               ShortRead_1.42.0           
[33] GenomicAlignments_1.20.0    Rsamtools_2.0.0            
[35] Biostrings_2.52.0           XVector_0.24.0             
[37] DESeq2_1.24.0               SummarizedExperiment_1.14.0
[39] DelayedArray_0.10.0         BiocParallel_1.18.0        
[41] matrixStats_0.54.0          Biobase_2.44.0             
[43] GenomicRanges_1.36.0        GenomeInfoDb_1.20.0        
[45] IRanges_2.18.1              S4Vectors_0.22.0           
[47] BiocGenerics_0.30.0         edgeR_3.26.4               
[49] limma_3.40.2                ggbiplot_0.55              
[51] scales_1.0.0                plyr_1.8.4                 
[53] ggplot2_3.1.1               gplots_3.0.1.1             

loaded via a namespace (and not attached):
  [1] R.utils_2.8.0                 tidyselect_0.2.5             
  [3] RSQLite_2.1.1                 htmlwidgets_1.3              
  [5] DESeq_1.36.0                  munsell_0.5.0                
  [7] codetools_0.2-16              withr_2.1.2                  
  [9] colorspace_1.4-1              GOSemSim_2.10.0              
 [11] knitr_1.23                    rstudioapi_0.10              
 [13] pscl_1.5.2                    DOSE_3.10.1                  
 [15] labeling_0.3                  git2r_0.25.2                 
 [17] KEGGgraph_1.44.0              urltools_1.7.3               
 [19] GenomeInfoDbData_1.2.1        mixsqp_0.1-97                
 [21] hwriter_1.3.2                 polyclip_1.10-0              
 [23] bit64_0.9-7                   farver_1.1.0                 
 [25] rprojroot_1.3-2               xfun_0.7                     
 [27] doParallel_1.0.14             R6_2.4.0                     
 [29] locfit_1.5-9.1                bitops_1.0-6                 
 [31] fgsea_1.10.0                  gridGraphics_0.4-1           
 [33] assertthat_0.2.1              promises_1.0.1               
 [35] ggraph_1.0.2                  nnet_7.3-12                  
 [37] enrichplot_1.4.0              gtable_0.3.0                 
 [39] workflowr_1.4.0               rlang_0.3.4                  
 [41] splines_3.6.0                 rtracklayer_1.44.0           
 [43] lazyeval_0.2.2                acepack_1.4.1                
 [45] europepmc_0.3                 BiocManager_1.30.4           
 [47] yaml_2.2.0                    reshape2_1.4.3               
 [49] backports_1.1.4               httpuv_1.5.2                 
 [51] qvalue_2.16.0                 Hmisc_4.2-0                  
 [53] tools_3.6.0                   ggplotify_0.0.3              
 [55] affyio_1.54.0                 ggridges_0.5.1               
 [57] Rcpp_1.0.1                    base64enc_0.1-3              
 [59] progress_1.2.2                zlibbioc_1.30.0              
 [61] purrr_0.3.2                   RCurl_1.95-4.12              
 [63] prettyunits_1.0.2             rpart_4.1-15                 
 [65] viridis_0.5.1                 cowplot_0.9.4                
 [67] ggrepel_0.8.1                 cluster_2.0.9                
 [69] fs_1.3.1                      magrittr_1.5                 
 [71] data.table_1.12.2             DO.db_2.9                    
 [73] triebeard_0.3.0               truncnorm_1.0-8              
 [75] SQUAREM_2017.10-1             whisker_0.3-2                
 [77] ProtGenerics_1.16.0           aroma.light_3.14.0           
 [79] mime_0.7                      hms_0.4.2                    
 [81] evaluate_0.14                 xtable_1.8-4                 
 [83] XML_3.98-1.20                 gridExtra_2.3                
 [85] compiler_3.6.0                biomaRt_2.40.0               
 [87] tibble_2.1.3                  KernSmooth_2.23-15           
 [89] crayon_1.3.4                  R.oo_1.22.0                  
 [91] htmltools_0.3.6               later_0.8.0                  
 [93] Formula_1.2-3                 tidyr_0.8.3                  
 [95] geneplotter_1.62.0            DBI_1.0.0                    
 [97] tweenr_1.0.1                  rappdirs_0.3.1               
 [99] Matrix_1.2-17                 R.methodsS3_1.7.1            
[101] gdata_2.18.0                  igraph_1.2.4.1               
[103] pkgconfig_2.0.2               rvcheck_0.1.3                
[105] foreign_0.8-71                foreach_1.4.4                
[107] xml2_1.2.0                    annotate_1.62.0              
[109] stringr_1.4.0                 digest_0.6.19                
[111] graph_1.62.0                  rmarkdown_1.13               
[113] fastmatch_1.1-0               htmlTable_1.13.1             
[115] curl_3.3                      shiny_1.3.2                  
[117] gtools_3.8.1                  jsonlite_1.6                 
[119] viridisLite_0.3.0             pillar_1.4.1                 
[121] lattice_0.20-38               KEGGREST_1.24.0              
[123] httr_1.4.0                    survival_2.44-1.1            
[125] GO.db_3.8.2                   interactiveDisplayBase_1.22.0
[127] glue_1.3.1                    UpSetR_1.4.0                 
[129] iterators_1.0.10              png_0.1-7                    
[131] bit_1.1-14                    Rgraphviz_2.28.0             
[133] ggforce_0.2.2                 blob_1.1.1                   
[135] latticeExtra_0.6-28           caTools_1.17.1.2             
[137] memoise_1.1.0